﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace Soapi.Contrib.ValueConverters
{
    public class ViewsConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if(value==null)
            {
                return "0";
            }
            var count = System.Convert.ToDouble(value);

            if (count < 1000)
            {
                return count.ToString();
            }

            return (count / 1000).ToString(count % 1000 == 0 ? "" : "F1") + 'k';
        }



        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}